<?php
namespace Admin\Controller;
use Think\Controller;
/**
 * Class MessageController
 * @package Admin\Controller
 * 2017-12-13   留言信息
 */
class MessageController extends AdminBasicController{

    public $message = '';
    public function _initialize(){
        $this->checkLogin();
        $this->message = D('Message');
    }

    /**
     * 留言列表
     * @author mss
     * @time 2017-12-14
     */
    public function messageList(){
        $shop_id = I('get.shop_id');
        $where = array();
        $param = array();
        $where['status'] = 0;
        $order = 'ctime DESC';
        /**按留言名称或手机号标题搜索*/
        if(!empty(trim(I('request.title')))){
            $title = trim(I('request.title'));
            $where['name|phone'] = array('LIKE','%'.$title.'%');
            $param['title'] = $title;
        }
        /**按商家名称或账号搜索*/
        if(!empty(trim(I('request.name')))){
            $name = trim(I('request.name'));
            $w['name|account'] = array('LIKE','%'.$name.'%');
            $w['status'] = array('NEQ',9);
            $ids = M('Shop')->where($w)->order('ctime DESC')->getField('shop_id',true);
            $where['shop_id'] = array('IN',$ids);
            $param['name'] = $name;
        }
        /**按发布时间查找*/
        if(!empty(I('request.start_time')) && !empty(I('request.end_time'))){
            $start_time = I('request.start_time');
            $this->assign("start_time",$start_time);
            $end_time = I('request.end_time');
            $this->assign("end_time",$end_time);
            $w['ctime'] = array(array('EGT',strtotime($start_time)),array('ELT',strtotime($end_time)),'and');
            $param['start_time'] = I('request.start_time');
            $param['end_time'] = I('request.end_time');
        }

        /**从商家列表跳转过来*/
        if(!empty($shop_id)){
            $where['shop_id'] = $shop_id;
            $param['shop_id'] = $shop_id;
            $this->assign('shop_id',$shop_id);
        }

        $list = $this->message->selectMessage($where,$order,15,$param);
        $data = $list['list'];
        foreach($data as $k=>$v){
            $data[$k]['shop_name'] = M('Shop')->where(array('shop_id'=>$v['shop_id']))->getField('name');
        }

        $this->assign('list',$data);
        $this->assign('page',$list['page']);
        $this->assign('request',$_REQUEST);

        $this->display('messageList');
    }


}